package top.hzy520.admin.config;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * @Author: HouZeYu
 * @Description:  自定义密码验证
 * @Date: Created in 19:29 2018/7/29
 */
public class CredentialsMatcher extends SimpleCredentialsMatcher {
    @Autowired
    private BCryptPasswordEncoder passwordEncoder;
    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
       UsernamePasswordToken usernamePasswordToken= (UsernamePasswordToken) token;
       String currentpassword=  String.valueOf( usernamePasswordToken.getPassword())  ;
       String  dbpassword=String.valueOf(info.getCredentials());
        return passwordEncoder.matches(currentpassword,dbpassword);
    }
}
